import 'package:flutter/material.dart';


// 将MessagePage定义为StatefulWidget
class MessagePage extends StatefulWidget {
  const MessagePage({Key? key}) : super(key: key);

  @override
  _MessagePageState createState() => _MessagePageState();
}


class _MessagePageState extends State<MessagePage> {
  Future<void> _userPro() async {
    // 使用路由名称将用户重定向到消息页面
    if (mounted) {
      Navigator.of(context).pushReplacementNamed(
        '/main',
        arguments: 3, // 指定激活的底部导航索引
      );
    }
  }
  final List<NotificationItem> notifications = [
    NotificationItem(
      title: '欢迎加入悦享老年大家庭！',
      content: '承蒙欢爱，欢迎你加入悦享老年的一个大家庭中，在这里可以帮助您记录美好时刻以及提醒',
      dateTime: '2022-09-24',
      imageUrl: 'assets/img.png', // 请替换为实际图片路径
      isVIP: true,
    ),
    NotificationItem(
      title: '加入超品会员，获得923元超级大礼包！',
      content: '• 精选护肤化妆，包邮到家\n• 亚洲特供视频会员\n• 458天追剧会员时长',
      dateTime: '2022-09-15',
      imageUrl: 'assets/img.png', // 请替换为实际图片路径
      isVIP: true,
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('系统通知'),
        actions: <Widget>[
          IconButton(
            onPressed: (){
              _userPro();
          },
              icon: Image.asset('assets/break.png')
          )
        ],
      ),
      body: ListView.builder(
        itemCount: notifications.length,
        itemBuilder: (context, index) {
          var notification = notifications[index];
          return Card(
            color: Theme.of(context).cardColor, // 卡片背景色
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    notification.title,
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: notification.isVIP ? Colors.orange : Colors.white,
                    ),
                  ),
                  const SizedBox(height: 8),
                  Text(notification.content),
                  const SizedBox(height: 8),
                  notification.imageUrl != null
                      ? Image.asset(notification.imageUrl) // 显示通知图片
                      : const SizedBox(),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(notification.dateTime, style: const TextStyle(color: Colors.grey)),
                      /*ElevatedButton(
                        onPressed: () {
                          // 按钮点击事件
                        },
                        child: const Text('点击查看'),
                      ),*/
                    ],
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}

class NotificationItem {
  final String title;
  final String content;
  final String dateTime;
  final String imageUrl;
  final bool isVIP;

  NotificationItem({
    required this.title,
    required this.content,
    required this.dateTime,
    required this.imageUrl,
    this.isVIP = false,
  });
}